int cet_gbfprintf(gbfile *stream, const cet_cs_vec_t *src_vec, const char *fmt, ...)
{
- char buff[128];
- int res, ct;
+ int res;
+ char *cout;
va_list args;
- char *cout = buff;
va_start(args, fmt);
- ct = vsnprintf(buff, sizeof(buff), fmt, args);
+ xvasprintf(&cout, fmt, args);
va_end(args);
- if (ct >= (int)sizeof(buff)) {
- cout = xmalloc(ct + 1);
- va_start(args, fmt);
- vsnprintf(cout, ct + 1, fmt, args);
- va_end(args);
- }
-
if (global_opts.charset != src_vec)
{
if (src_vec != &cet_cs_vec_utf8) {
char *ctemp = cet_str_any_to_utf8(cout, src_vec);
- if (cout != buff) xfree(cout);
+ xfree(cout);
cout = ctemp;
}
if (global_opts.charset != &cet_cs_vec_utf8) {
char *ctemp = cet_str_utf8_to_any(cout, global_opts.charset);
- if (cout != buff) xfree(cout);
+ xfree(cout);
cout = ctemp;
}
}
res = gbfprintf(stream, "%s", cout);
- if (cout != buff) xfree(cout);
+ xfree(cout);
return res;
}
/* 1 to enable all the filters. */
#undef FILTERS_ENABLED
+/* Define to 1 if you have the <inttypes.h> header file. */
+#undef HAVE_INTTYPES_H
+
/* Defined if you have libexpat */
#undef HAVE_LIBEXPAT
/* Define to 1 if you have the `z' library (-lz). */
#undef HAVE_LIBZ
+/* Define to 1 if you have the <memory.h> header file. */
+#undef HAVE_MEMORY_H
+
/* Define to 1 if you have the `nanosleep' function. */
#undef HAVE_NANOSLEEP
/* Define to 1 if you have the `sleep' function. */
#undef HAVE_SLEEP
+/* Define to 1 if you have the <stdint.h> header file. */
+#undef HAVE_STDINT_H
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#undef HAVE_STDLIB_H
+
+/* Define to 1 if you have the <strings.h> header file. */
+#undef HAVE_STRINGS_H
+
+/* Define to 1 if you have the <string.h> header file. */
+#undef HAVE_STRING_H
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#undef HAVE_SYS_STAT_H
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#undef HAVE_SYS_TYPES_H
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#undef HAVE_UNISTD_H
+
+/* Define if we have va_copy */
+#undef HAVE_VA_COPY
+
+/* Define as 1 if your va_list type is an array */
+#undef HAVE_VA_LIST_AS_ARRAY
+
+/* Define if we have __va_copy */
+#undef HAVE___VA_COPY
+
/* 1 to enable as many formats as possible */
#undef MAXIMAL_ENABLED
/* 1 to enable shapefile support */
#undef SHAPELIB_ENABLED
+/* Define to 1 if you have the ANSI C header files. */
+#undef STDC_HEADERS
+
/* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */
#undef WORDS_BIGENDIAN
done
+#
+# Checks for how the system handles va_list
+# paul.bromiley@man.ac.uk
+#
+{ echo "$as_me:$LINENO: checking for va_copy" >&5
+echo $ECHO_N "checking for va_copy... $ECHO_C" >&6; }
+if test "${ac_cv_c_va_copy+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <stdarg.h>
+int
+main ()
+{
+va_list ap1, ap2;
+ va_copy(ap1,ap2);
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext &&
+ $as_test_x conftest$ac_exeext; then
+ ac_cv_c_va_copy="yes"
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_cv_c_va_copy="no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+ conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_c_va_copy" >&5
+echo "${ECHO_T}$ac_cv_c_va_copy" >&6; }
+if test "$ac_cv_c_va_copy" = "yes"
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_VA_COPY 1
+_ACEOF
+
+fi
+{ echo "$as_me:$LINENO: checking for __va_copy" >&5
+echo $ECHO_N "checking for __va_copy... $ECHO_C" >&6; }
+if test "${ac_cv_c___va_copy+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <stdarg.h>
+int
+main ()
+{
+va_list ap1, ap2;
+ __va_copy(ap1,ap2);
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && {
+ test -z "$ac_c_werror_flag" ||
+ test ! -s conftest.err
+ } && test -s conftest$ac_exeext &&
+ $as_test_x conftest$ac_exeext; then
+ ac_cv_c___va_copy="yes"
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ ac_cv_c___va_copy="no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+ conftest$ac_exeext conftest.$ac_ext
+
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_c___va_copy" >&5
+echo "${ECHO_T}$ac_cv_c___va_copy" >&6; }
+if test "$ac_cv_c___va_copy" = "yes"
+then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE___VA_COPY 1
+_ACEOF
+
+fi
+
+#
+# Does this platform require array notation to assign to a va_list?
+#
+{ echo "$as_me:$LINENO: checking va_list assignments need array notation" >&5
+echo $ECHO_N "checking va_list assignments need array notation... $ECHO_C" >&6; }
+if test "${ac_cv_valistisarray+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test "$cross_compiling" = yes; then
+ ac_cv_valistisarray=false
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <stdlib.h>
+ #include <stdarg.h>
+ void foo(int i, ...) {
+ va_list ap1, ap2;
+ va_start(ap1, i);
+ ap2 = ap1;
+ if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); }
+ va_end(ap1); va_end(ap2);
+ }
+ int main()
+ { foo(0, 123); return(0); }
+_ACEOF
+rm -f conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_link") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (case "(($ac_try" in
+ *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+ *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+ (eval "$ac_try") 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_valistisarray=false
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+ac_cv_valistisarray=true
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+
+
+fi
+
+
+if test "$ac_cv_valistisarray" = true ; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_VA_LIST_AS_ARRAY 1
+_ACEOF
+
+ { echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6; }
+else
+ { echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6; }
+fi
ac_config_files="$ac_config_files Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty"
cat >confcache <<\_ACEOF
$ac_cs_success || { (exit 1); exit 1; }
fi
+
# AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
AC_CHECK_FUNCS([nanosleep sleep])
+#
+# Checks for how the system handles va_list
+# paul.bromiley@man.ac.uk
+#
+dnl **** Check for va_copy ****
+AC_CACHE_CHECK([for va_copy], ac_cv_c_va_copy,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>]], [[va_list ap1, ap2;
+ va_copy(ap1,ap2);
+ ]])],[ac_cv_c_va_copy="yes"],[ac_cv_c_va_copy="no"])
+ )
+if test "$ac_cv_c_va_copy" = "yes"
+then
+ AC_DEFINE(HAVE_VA_COPY, 1, [Define if we have va_copy])
+fi
+AC_CACHE_CHECK([for __va_copy], ac_cv_c___va_copy,
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdarg.h>]], [[va_list ap1, ap2;
+ __va_copy(ap1,ap2);
+ ]])],[ac_cv_c___va_copy="yes"],[ac_cv_c___va_copy="no"])
+ )
+if test "$ac_cv_c___va_copy" = "yes"
+then
+ AC_DEFINE(HAVE___VA_COPY, 1, [Define if we have __va_copy])
+fi
+
+#
+# Does this platform require array notation to assign to a va_list?
+#
+AC_MSG_CHECKING(va_list assignments need array notation)
+AC_CACHE_VAL(ac_cv_valistisarray,
+ [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
+ #include <stdarg.h>
+ void foo(int i, ...) {
+ va_list ap1, ap2;
+ va_start(ap1, i);
+ ap2 = ap1;
+ if (va_arg(ap2, int) != 123 || va_arg(ap1, int) != 123) { exit(1); }
+ va_end(ap1); va_end(ap2);
+ }
+ int main()
+ { foo(0, 123); return(0); }]])],[ac_cv_valistisarray=false],[ac_cv_valistisarray=true],[ac_cv_valistisarray=false])])
+
+if test "$ac_cv_valistisarray" = true ; then
+ AC_DEFINE(HAVE_VA_LIST_AS_ARRAY, 1, [Define as 1 if your va_list type is an array])
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
AC_CONFIG_FILES([Makefile gbversion.h xmldoc/makedoc tools/mkcapabilities win32/gpsbabel.rc jeeps/Makefile shapelib/Makefile zlib/empty])
AC_OUTPUT
+
# define NORETURN void
#endif
+#ifndef HAVE_VA_COPY
+# ifdef __va_copy
+# define va_copy(DEST,SRC) __va_copy((DEST),(SRC))
+# else
+# ifdef HAVE_VA_LIST_AS_ARRAY
+# define va_copy(DEST,SRC) (*(DEST) = *(SRC))
+# else
+# define va_copy(DEST,SRC) ((DEST) = (SRC))
+# endif
+# endif
+#endif
+
/*
* Common definitions. There should be no protocol or file-specific
* data in this file.
void rtrim(char *s);
char * lrtrim(char *s);
int xasprintf(char **strp, const char *fmt, ...);
+int xvasprintf(char **strp, const char *fmt, va_list ap);
char *strupper(char *src);
char *strlower(char *src);
signed int get_tz_offset(void);
}
/*
- * gbfprintf: (as fprintf)
+ * gbvfprintf: (as vfprintf)
*/
-int
-gbfprintf(gbfile *file, const char *format, ...)
+int gbvfprintf(gbfile *file, const char *format, va_list ap)
{
int len;
for (;;) {
va_list args;
- va_start(args, format);
+ va_copy(args, ap);
len = vsnprintf(file->buff, file->buffsz, format, args);
va_end(args);
return gbfwrite(file->buff, 1, len, file);
}
+/*
+ * gbfprintf: (as fprintf)
+ */
+
+int
+gbfprintf(gbfile *file, const char *format, ...)
+{
+ va_list args;
+ int result;
+
+ va_start(args, format);
+ result = gbvfprintf(file, format, args);
+ va_end(args);
+
+ return result;
+}
+
/*
* gbfputc: (as fputc)
*/
int gbfgetc(gbfile *file);
char *gbfgets(char *buf, int len, gbfile *file);
+int gbvfprintf(gbfile *file, const char *format, va_list ap);
int gbfprintf(gbfile *file, const char *format, ...);
int gbfputc(int c, gbfile *file);
int gbfputs(const char *s, gbfile *file);
int
xasprintf(char **strp, const char *fmt, ...)
+{
+ va_list args;
+ int res;
+
+ va_start(args, fmt);
+ res = xvasprintf(strp, fmt, args);
+ va_end(args);
+
+ return res;
+}
+
+int
+xvasprintf(char **strp, const char *fmt, va_list ap)
{
/* From http://perfec.to/vsnprintf/pasprintf.c */
/* size of first buffer malloc; start small to exercise grow routines */
return -1;
}
- va_start(args, fmt);
+ va_copy(args, ap);
outsize = vsnprintf(buf, bufsize, fmt, args);
va_end(args);
return outsize;
}
+
/*
* Duplicate a pascal string into a normal C string.
*/